package com.fottas.adware.portal.config;

import com.fottas.adware.portal.domain.QueueEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置
 */
@Configuration
public class RabbitMqConfig {

    /**
     * 短息验证实际消费队列所绑定的交换机
     */
    @Bean
    DirectExchange smsDirect(){
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.QUEUE_SMS_CANCEL.getExchange())
                .durable(true)
                .build();
    }

    /**
     * 短信验证实际消费队列
     */
    @Bean
    public Queue smsQueue() {
        return new Queue(QueueEnum.QUEUE_SMS_CANCEL.getName());
    }

    /**
     * 将短信验证队列绑定到交换机
     */
    @Bean
    Binding smsBinding(DirectExchange smsDirect,Queue smsQueue){
        return BindingBuilder
                .bind(smsQueue)
                .to(smsDirect)
                .with(QueueEnum.QUEUE_SMS_CANCEL.getRouteKey());
    }

}
